
%module acquirepy

#define SwigPyIterator AcquirePy_SwigPyIterator
%{
#define SwigPyIterator AcquirePy_SwigPyIterator
%}

// PRINTF_LIKE is undefined to ensure the declaration are not polluted
%define PRINTF_LIKE(a, b)
%enddef
%define EXPORTED
%enddef
%define EXPORTABI
%enddef
%include "typemaps.i"
%include "std_string.i"
%include "std_map.i"

%typemap(out) const char ** {
   int len;
   int i;
   len = 0;
   while ($1[len]) len++;
   $result = PyList_New(len);
   for (i = 0; i < len; i++)
      PyList_SetItem($result, i, PyString_FromString($1[i]));
}

%template() std::pair<std::string, std::string>;
%template(map_si)  std::map<std::string, std::string>;

%{
#include <unistd.h>
#include "acquire_client.h"
#include "acquire_compute.h"
#include "acquire_common.h"
#include "acquire_common_private.h"

const char *acquirePythonGetDSName(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.name;
}

const char *acquirePythonGetDSDecryptionKey(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.decryptionkey;
}

int acquirePythonGetDSBlockCount(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.blockcount;
}

int acquirePythonGetDSBlockSize(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.blocksize;
}

int acquirePythonGetDSInstanceCount(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.instancecount;
}

int acquirePythonGetDSIsWorkPacket(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.isworkpacket;
}

int acquirePythonGetDSIsResults(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.isresults;
}

int acquirePythonGetDSIsComplete(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.iscomplete;
}

int acquirePythonGetDSIsValid(acquireCommonDataStoreInfo dsinfo)
{
   return dsinfo.isvalid;
}

const char *acquirePythonGetDSWIDataStoreID(acquireComputeDataStoreWorkInstanceInfo dswiinfo)
{
   return dswiinfo.datastoreid;
}

int acquirePythonGetDSWILocalInstanceNumber(acquireComputeDataStoreWorkInstanceInfo dswiinfo)
{
   return dswiinfo.localinstancenumber;
}

int acquirePythonUploadToDataStore(const char *store_id, const char *inputdirectory, int tblocksize, const char *realkeyname)
{
   int blocksdone = 0;
   int cancelflag = 0;
   return acquireCommonUploadToDataStore(store_id, inputdirectory, tblocksize, &blocksdone, &cancelflag, realkeyname);
}

acquireCommonDataStoreInfo acquirePythonCreateDataStore(const char *inputdirectory,
   const char *enckeyname, const char *deckeyname,
   int addspecifickeys, int tblocksize)
{
   acquireCommonDataStoreInfo dsinfo;
   dsinfo.name = NULL;
   dsinfo.decryptionkey = deckeyname;
   dsinfo.blockcount = -1;
   dsinfo.blocksize = tblocksize;
   dsinfo.instancecount = 0;
   dsinfo.isworkpacket = 0;
   dsinfo.isresults = 1;
   dsinfo.iscomplete = 0;
   int64_t remotespace = -1;
   int cancelled = 0;
   int retcode;
   dsinfo.name = acquireCommonCreateDataStore(inputdirectory, enckeyname, deckeyname,
      addspecifickeys, tblocksize, &remotespace, &(dsinfo.blockcount), &cancelled);
   dsinfo.isvalid = (dsinfo.name != NULL);
   return dsinfo;
}

const std::map<std::string, std::string> &acquirePythonGetCached()
{
   return (state.resolver)->getCachedMap();
}

void acquirePythonSleep(int secs)
{
   sleep(secs);
}

%}

%include "acquire_client.h"
%include "acquire_compute.h"
%include "acquire_common.h"
%import "acquire_client.h"
%import "acquire_compute.h"
%import "acquire_common.h"

extern const char *acquirePythonGetDSName(acquireCommonDataStoreInfo dsinfo);

extern const char *acquirePythonGetDSDecryptionKey(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSBlockCount(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSBlockSize(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSInstanceCount(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSIsWorkPacket(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSIsResults(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSIsComplete(acquireCommonDataStoreInfo dsinfo);

extern int acquirePythonGetDSIsValid(acquireCommonDataStoreInfo dsinfo);

extern const char *acquirePythonGetDSWIDataStoreID(acquireComputeDataStoreWorkInstanceInfo dswiinfo);

extern int acquirePythonGetDSWILocalInstanceNumber(acquireComputeDataStoreWorkInstanceInfo dswiinfo);

extern int acquirePythonUploadToDataStore(const char *store_id, const char *inputdirectory, int tblocksize, const char *realkeyname);

extern acquireCommonDataStoreInfo acquirePythonCreateDataStore(const char *inputdirectory,
   const char *enckeyname, const char *deckeyname,
   int addspecifickeys, int tblocksize);

extern const std::map<std::string, std::string> &acquirePythonGetCached();

extern void acquirePythonSleep(int secs);
